#ifndef WGET_H
#define WGET_H


//----------------------------------------------------------------------------//
// I N C L U D E   Q T                                                        //
//----------------------------------------------------------------------------//
#include <QObject>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkReply>


//----------------------------------------------------------------------------//
// T Y P E S   &   D E F I N I T I O N S                                      //
//----------------------------------------------------------------------------//
// enum de valeur de retour pour les fonctions wget
typedef enum
{
  WGET_OK,
  WGET_NOK,
  WGET_NO_RATE
} ReturnWget_t;


//----------------------------------------------------------------------------//
// C L A S S   D E C L A R A T I O N                                          //
//----------------------------------------------------------------------------//
class Wget : public QObject
{
    Q_OBJECT
  public:
    //------------------------------------------------------------------------//
    // C O N T R U C T O R S                                                  //
    //------------------------------------------------------------------------//
    // explicit signifie que l'on doit obligatoirement appeler le constructeur
    Wget(QObject *parent = 0);


    //------------------------------------------------------------------------//
    // P U B L I C   M E T H O D S   D E C L A R A T I O N                    //
    //------------------------------------------------------------------------//
    // page
    void requestPage(QString url);
    QString getPage(void);
    // imdb
    void requestIMDb(QString title);
    QString getLinkIMDb(void);
    QString getRateIMDb(void);
    ReturnWget_t getStatusIMDb(void);
    // allocine
    void requestAllocine(QString title);
    QString getLinkAllocine(void);
    QString getRateAllocine(void);
    QString getPosterAllocine(void);
    ReturnWget_t getStatusAllocine(void);


  signals:
    //------------------------------------------------------------------------//
    // S I G N A L S                                                          //
    //------------------------------------------------------------------------//
    void finishedPage(void);
    void finishedIMDb(void);
    void finishedAllocine(void);


  public slots:
    //------------------------------------------------------------------------//
    // S L O T S                                                              //
    //------------------------------------------------------------------------//
    void replyPage(QNetworkReply *);
    void replyIMDb(QNetworkReply *);
    void replyAllocine(QNetworkReply *);


  private:
    //------------------------------------------------------------------------//
    // P R I V A T E   M E T H O D S   D E C L A R A T I O N                  //
    //------------------------------------------------------------------------//
    void parseDeanClatWorthyIMDb(QNetworkReply* reply);
    void parseIMDb(QNetworkReply* reply); // only ID


    //------------------------------------------------------------------------//
    // P R I V A T E   A T T R I B U T E S   D E C L A R A T I O N            //
    //------------------------------------------------------------------------//
    QNetworkAccessManager* NetworkManagerPage;
    QNetworkAccessManager* NetworkManagerIMDb;
    QNetworkAccessManager* NetworkManagerAllocine;
    // page
    QString Page;
    // imdb
    QString IMDbTitle;
    QString IMDbUrl;
    QString IMDbRate;
    ReturnWget_t IMDbStatus;
    // allocine
    QString AllocineTitle;
    QString AllocineUrl;
    QString AllocineRate;
    QString AllocinePoster;
    ReturnWget_t AllocineStatus;
};


#endif // WGET_H
